﻿using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;

namespace ADO.NET_Entity_Framework
{
    public static class EmployeeUtils
    {
        public static EntitySet<Territory> FindTerritories(this Employee employee)
        {
            using (NorthwindEntities context = new NorthwindEntities())
            {
                List<Territory> query = context.Territories.Where(
                    t => t.Employees.Any(
                        e => e.EmployeeID == employee.EmployeeID)).ToList();
                EntitySet<Territory> result = new EntitySet<Territory>();
                result.AddRange(query);
                return result;
            }
        }
    }
}
